const Validator = require("../validator/index")
export default class RequestConfig {
    constructor(param) {
        const {
            baseUrl = '',

            tokenPassWhiteList = [],

            successStatusCode = 200,
            successCode = 200,
            reloginCode = 401,

            refreshTokenNotificationKey = '',
            refreshTokenNotificationSuccessKey = '',

            accessTokenCacheKey = '',
        } = param || {}

        this.baseUrl = baseUrl;

        // "*...url" 结尾
        // "...url*" 开头
        // "!!!...url" 严格相等
        // "url" 包含
        this.tokenPassWhiteList = tokenPassWhiteList;

        this.successStatusCode = successStatusCode;
        this.successCode = successCode;
        this.reloginCode = reloginCode;

        this.refreshTokenNotificationKey = refreshTokenNotificationKey;
        this.refreshTokenNotificationSuccessKey = refreshTokenNotificationSuccessKey;

        this.accessTokenCacheKey = accessTokenCacheKey;

        valid.call(this);
    }
}

function valid() {
    let validator = new Validator();
    validator.add(this.baseUrl, "isNotEmpty", "leeCommonJs请配置 baseUrl");
    validator.add(this.refreshTokenNotificationKey, "isNotEmpty", "leeCommonJs请配置 refreshTokenNotificationKey");
    validator.add(this.refreshTokenNotificationSuccessKey, "isNotEmpty", "leeCommonJs请配置 refreshTokenNotificationSuccessKey");
    validator.add(this.accessTokenCacheKey, "isNotEmpty", "leeCommonJs请配置 accessTokenCacheKey");
    let errMsg = validator.start();
    if (errMsg) {
        throw new Error(errMsg);
    }
}